package com.guodx.study.springboot.d02.controller;

import com.guodx.study.springboot.d02.po.School;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class Hello {

    @Autowired
    private School school;

    @ResponseBody
    @GetMapping("/hello/{name}")
    public String hello(@PathVariable("name") String name){
        return "hello, " + name;
    }

    /**
     * 输出注入的信息
     * @return
     */
    @ResponseBody
    @GetMapping("/print-school")
    public School printSchool(){
        return school;
    }

    /**
     * 不存在配置项时，默认值为haha
     */
    @Value("${newName:haha}")
    private String newName;

    @ResponseBody
    @GetMapping("upd-name")
    public School updName(){
        school.setName(newName);
        return school;
    }
}
